<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>20.Currying_function</title>
</head>
<body>
<div id="app"></div>

<script src="lib/react.development.js"></script>
<script src="lib/react-dom.development.js"></script>
<script src="lib/babel.min.js"></script>

<script type="text/babel">
   class Form extends React.Component{
       state ={
           username: '',
           password:''
       }

       submit = (event)=>{
           event.preventDefault();
           const {username,password} =this.state;
           console.log(username,password);
       }

       handleForm = (type)=>{
           return (event)=>{
               this.setState({[type]:event.target.value});
           }
       }

       render() {
           return (
               <div>
                   <form onSubmit={this.submit}>
                       {
                           /* <!-- 这里的函数一上来就会执行为函数的type赋值，然后函数执行完毕会返回一个函数
                       当事件触发的时候会调用返回的函数将event传递给内部的函数-->*/
                       }

                       <input type="text" onChange={this.handleForm("username")}/>
                       <input type="password" onChange={this.handleForm("password")}/>
                       <input type="submit" value="登录"/>
                   </form>
               </div>
           );
       }
   }

    ReactDOM.render(<Form/>,document.getElementById("app"))
</script>
</body>
</html>